#include <stdio.h>

#include "LinkedList.c"

void test_node() {
	Node *node = getNode(0.0f);
		
	printf("\n---------------------------------------------------------- Make node routine\n");

	dumpNode(node);
	setNodeData(node, 11.0f);
	dumpNode(node);

	deleteNode(node);

}

void test_list() {

	Node *node1 = getNode(11);
	Node *node2 = getNode(20);
	List *l = getList(node1);
	
	printf("\n---------------------------------------------------------- Make list routine\n");
	dumpHeadTail(l);
	
	printf("add one node in head");
	addInHead(l, node2);
	dumpHeadTail(l);

	printf("remove tail");
	removeTail(l);
	dumpHeadTail(l);

	deleteNode(node2);
	deleteList(l);

}

void test_iterator() {
	Node *node1 = getNode(11);
	Node *node2 = getNode(20);
	Node *node3 = getNode(24);
	Node *node4 = getNode(42);
	List *l = getList(node1);
	Iterator *itr = getIterator(l);

	printf("---------------------------------------------------------- Make list with iterator routine\n");
	printf("\nadd nodes");
	addInHead(l, node2); addInHead(l, node3); addInHead(l, node4);
	dumpTraverse(itr);

	printf("\n sum: ");
	printf("%f",sum(itr));
	printf("\n average: ");
	printf("%f",average(itr));
	printf("\n deviation: ");
	printf("%f",deviation(itr));


	deleteIterator(itr);
	deleteList(l);

	printf("\n");
}

void test_addelement() {
	Iterator *itr = getListIterator();
	int l = 0;
	int i = 0;
	float *array;

	printf("---------------------------------------------------------- Use only iterator routine\n");

	addElement(itr, 1.0f);
	addElement(itr, 2.0f);
	addElement(itr, 3.0f);
	addElement(itr, 4.0f);
	dumpTraverse(itr);

	l = itr->list->size;
	array = toArray(itr);
	for (i=0; i<l; i++) {
		printf("\narray[%d] : %f", i, array[i]);
	}

	printf("\n\n");
}

/*void test_avg_dev() {

	Iterator *itr = getListIterator();
	addElement(itr, );
}*/

int main() {
	printf("\ndriver test for linked list.\n");

	test_node();
	test_list();
	test_iterator();
	test_addelement();

	return 0;
}


